{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c7da8e86",
   "metadata": {},
   "source": [
    "# Pandas🐼 vs SQL📅"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "913c6465",
   "metadata": {},
   "source": [
    "## Loading the Required Libraries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "937263c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "import sqlite3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be180706",
   "metadata": {},
   "source": [
    "## Extra Setup for Database and Python Connectivity"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7b43405f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tables in database are: [('Salaries',)]\n",
      "Columns in the Salaries Table are: Id, EmployeeName, JobTitle, BasePay, OvertimePay, OtherPay, Benefits, TotalPay, TotalPayBenefits, Year, Notes, Agency, Status, "
     ]
    }
   ],
   "source": [
    "# Establish connection between python program and db\n",
    "conn = sqlite3.connect('data/database.sqlite')\n",
    "\n",
    "# To execute sql query and hold result cursor is required\n",
    "cursor = conn.cursor()\n",
    "\n",
    "# Execute sql query with the help of cursor object\n",
    "# Fetch all tables from the database\n",
    "cursor.execute(\"SELECT name FROM sqlite_master WHERE type='table'\")\n",
    "print(\"Tables in database are:\", cursor.fetchall())\n",
    "\n",
    "# Fetch Salaries table Info\n",
    "cursor.execute(\"PRAGMA table_info('Salaries')\")\n",
    "cols = cursor.fetchall()\n",
    "\n",
    "print(\"Columns in the Salaries Table are:\", end=\" \")\n",
    "for col in cols:\n",
    "    print(col[1], end=\", \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1f09ecd7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "e413c858",
   "metadata": {},
   "source": [
    "## Reading Data With Pandas vs SQL"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
